/*
 * DepartmentValueDisplay.java
 *
 * Created on 07 January 2004, 07:34
 * Copyright (C) 2004, Velocityme Partnership
 */

package com.velocityme.client.gui.node.contactable.department;

import com.velocityme.client.gui.ValueListModel;
import com.velocityme.client.gui.contactdetail.ContactDetailTableModel;
import com.velocityme.valueobjects.ContactableValue;
import com.velocityme.valueobjects.ContactDetailValue;
import com.velocityme.valueobjects.DepartmentValue;
import com.velocityme.valueobjects.NodeValue;
import java.util.Collection;

/**
 *
 * @author  Robert Crida Work
 */
public class DepartmentValueDisplay extends javax.swing.JPanel {
    
    private DepartmentValue m_departmentValue;
    private ContactDetailTableModel m_modelContactDetails;
    
    /** Creates new form DepartmentValueDisplay */
    public DepartmentValueDisplay(DepartmentValue p_departmentValue, ContactDetailValue[] p_contactDetailValues) {
        initComponents();
        setDepartmentValue(p_departmentValue, p_contactDetailValues);
    }
    
    public void setDepartmentValue(DepartmentValue p_departmentValue, ContactDetailValue[] p_contactDetailValues) {
        ContactableValue contactableValue = p_departmentValue.getContactableValue();
        if (contactableValue != null) {
            NodeValue nodeValue = contactableValue.getNodeValue();
            if (nodeValue != null) {
                if (nodeValue.nameHasBeenSet())
                    jTextFieldName.setText(nodeValue.getName());
                if (nodeValue.descriptionHasBeenSet())
                    jTextAreaDescription.setText(nodeValue.getDescription());
            }
        }
        m_modelContactDetails.setContactDetails(p_contactDetailValues);
        m_departmentValue = p_departmentValue;
    }
    
    public DepartmentValue getDepartmentValue() {
        if (m_departmentValue.getContactableValue() == null)
            m_departmentValue.setContactableValue(new ContactableValue());
        if (m_departmentValue.getContactableValue().getNodeValue() == null)
            m_departmentValue.getContactableValue().setNodeValue(new NodeValue());
        m_departmentValue.getContactableValue().getNodeValue().setName(jTextFieldName.getText());
        m_departmentValue.getContactableValue().getNodeValue().setDescription(jTextAreaDescription.getText());
        return m_departmentValue;
    }
    
    public ContactDetailValue[] getContactDetailValues() {
        return m_modelContactDetails.getElements();
    }
    
    public void setEditable(boolean p_editable) {
        jTextFieldName.setEditable(p_editable);
        jTextAreaDescription.setEditable(p_editable);
        m_modelContactDetails.setEditable(p_editable);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelIcon = new javax.swing.JLabel();
        jLabelName = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        Description = new javax.swing.JLabel();
        jScrollPaneDescription = new javax.swing.JScrollPane();
        jTextAreaDescription = new javax.swing.JTextArea();
        jLabelContactDetails = new javax.swing.JLabel();
        jScrollPaneContactDetails = new javax.swing.JScrollPane();
        m_modelContactDetails = new ContactDetailTableModel();
        jTableContactDetails = new javax.swing.JTable(m_modelContactDetails);

        setLayout(new java.awt.GridBagLayout());

        jLabelIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/velocityme/client/icons/department-32x32.png")));
        add(jLabelIcon, new java.awt.GridBagConstraints());

        jLabelName.setText("Name:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jLabelName, gridBagConstraints);

        jTextFieldName.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jTextFieldName, gridBagConstraints);

        Description.setText("Description:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(Description, gridBagConstraints);

        jScrollPaneDescription.setPreferredSize(new java.awt.Dimension(106, 66));
        jTextAreaDescription.setEditable(false);
        jTextAreaDescription.setLineWrap(true);
        jTextAreaDescription.setWrapStyleWord(true);
        jScrollPaneDescription.setViewportView(jTextAreaDescription);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jScrollPaneDescription, gridBagConstraints);

        jLabelContactDetails.setText("Contact Details:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jLabelContactDetails, gridBagConstraints);

        jScrollPaneContactDetails.setPreferredSize(new java.awt.Dimension(106, 66));
        jScrollPaneContactDetails.setViewportView(jTableContactDetails);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jScrollPaneContactDetails, gridBagConstraints);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Description;
    private javax.swing.JLabel jLabelContactDetails;
    private javax.swing.JLabel jLabelIcon;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JScrollPane jScrollPaneContactDetails;
    private javax.swing.JScrollPane jScrollPaneDescription;
    private javax.swing.JTable jTableContactDetails;
    private javax.swing.JTextArea jTextAreaDescription;
    private javax.swing.JTextField jTextFieldName;
    // End of variables declaration//GEN-END:variables
    
}
